//图片切换
$(function(){
        var num=0;
        var timer;
        var hasStarted = false;
        $(".banner .left").click(function(){
            stop();
            --num;
            num = num%$(".pic li").size();
            showpic(num);
        });
        $(".banner .right").click(function(){
            stop();
            ++num;
            num = num%$(".pic li").size();
            showpic(num);
        });
        function showpic(index){
            $(".pic li").eq(index).show().siblings().hide();
            $(".dot li").eq(index).css("background","red").siblings().css("background","#fff");
        }
        
        function start() {
            if(!hasStarted) {
                hasStarted = true;
                timer = setInterval(function(){
                    showpic(num);
                    num++;
                    if(num== $(".pic li").size()){
                        num =0;
                    }
                },2000);
            }
        }
        function stop() {
            clearInterval(timer);
            hasStarted = false;
        }
        start();
    });

//图片切换
$(function(){
        var num=0;
        var timer;
        var hasStarted = false;
        $(".navSub .boxleft").click(function(){
            stop();
            --num;
            num = num%$(".box1 ul").size();
            showpic(num);
        });
        $(".navSub .boxright").click(function(){
            stop();
            ++num;
            num = num%$(".box1 ul").size();
            showpic(num);
        });
        function showpic(index){
            $(".box1 ul").eq(index).show().siblings().hide();
            $(".dot ul").eq(index).css("background","red").siblings().css("background","#fff");
        }
        
       /* function start() {
            if(!hasStarted) {
                hasStarted = true;
                timer = setInterval(function(){
                    showpic(num);
                    num++;
                    if(num== $(".box1 ul").size()){
                        num =0;
                    }
                },2000);
            }
        }
        function stop() {
            clearInterval(timer);
            hasStarted = false;
        }
        start();*/
    });

//页面导航滚动
$(function() {
	  $(window).scroll(function() {
	  //获取垂直滚动的距离
		/*var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;*/
	    var scrollTop = $(document).scrollTop();
	    if (scrollTop >= 400) {
	      $("#navSub").css({"top":"0","position":"fixed" });
	    }else {
	    $("#navSub").css({"top":"inherit","position":"relative" });
	      } 
	    });
	  });

function change_div(id){
	//热门书评
	  if (id == 'rmsp' ) 
	  { 
          document.getElementById("rmsp").style.display = 'block';
	      document.getElementById("rmtj").style.display = 'none'; 
	      document.getElementById("kxyk").style.display = 'none';
	      document.getElementById("bl").style.display = 'none';
	      document.getElementById("br").style.display = 'none';
	      document.getElementById("rmzz").style.display = 'none';
	  } 
	  //热门推荐
	  if (id == 'rmtj' ) 
	  {   
		  document.getElementById("bl").style.display = 'block';
          document.getElementById("br").style.display = 'block'; 
          document.getElementById("rmtj").style.display = 'block';
	      document.getElementById("rmsp").style.display = 'none'; 
	      document.getElementById("kxyk").style.display = 'none';
	      document.getElementById("rmzz").style.display = 'none';

	  } 
	  //开心一刻
	  if (id == 'kxyk' ) 
	  { 
          document.getElementById("kxyk").style.display = 'block';
	      document.getElementById("rmsp").style.display = 'none'; 
	      document.getElementById("rmtj").style.display = 'none';
	      document.getElementById("bl").style.display = 'none';
	      document.getElementById("br").style.display = 'none';
	      document.getElementById("rmzz").style.display = 'none';
	  } 
	  //热门作者
	 if (id == 'rmzz' ) 
	  {  
		  document.getElementById("rmzz").style.display = 'block';
          document.getElementById("kxyk").style.display = 'none';
	      document.getElementById("rmsp").style.display = 'none'; 
	      document.getElementById("rmtj").style.display = 'none';
	      document.getElementById("bl").style.display = 'none';
	      document.getElementById("br").style.display = 'none';
	  } 
	} 


function HideOrShowFont(obj) {
    if (obj == "a1") {
        document.getElementById("a1").style.color = "#2577e3"; 
        document.getElementById("a2").style.color = "#333";
        document.getElementById("a3").style.color = "#333";
        document.getElementById("a4").style.color = "#333";
        document.getElementById("a1").style.backgroundColor= "#537857"; 
        document.getElementById("a2").style.backgroundColor= "";
        document.getElementById("a3").style.backgroundColor= "";
        document.getElementById("a4").style.backgroundColor= "";
        

    }

   else if (obj == 'a2') {
        document.getElementById("a1").style.color = "#333"; 
        document.getElementById("a2").style.color = "#2577e3";
        document.getElementById("a3").style.color = "#333";
        document.getElementById("a4").style.color = "#333";
        document.getElementById("a1").style.backgroundColor= ""; 
        document.getElementById("a2").style.backgroundColor= "#537857";
        document.getElementById("a3").style.backgroundColor= "";
        document.getElementById("a4").style.backgroundColor= "";
    }
    else if (obj == 'a3') {
        document.getElementById("a1").style.color = "#333"; 
        document.getElementById("a2").style.color = "#333";
        document.getElementById("a3").style.color = "#2577e3";
        document.getElementById("a4").style.color = "#333";
        document.getElementById("a1").style.backgroundColor= ""; 
        document.getElementById("a2").style.backgroundColor= "";
        document.getElementById("a3").style.backgroundColor= "#537857";
        document.getElementById("a4").style.backgroundColor= "";
    }
    else if (obj == 'a4') {
        document.getElementById("a1").style.color = "#333"; 
        document.getElementById("a2").style.color = "#333";
        document.getElementById("a3").style.color = "#333";
        document.getElementById("a4").style.color = "#2577e3";
        document.getElementById("a1").style.backgroundColor= ""; 
        document.getElementById("a2").style.backgroundColor= "";
        document.getElementById("a3").style.backgroundColor= "";
        document.getElementById("a4").style.backgroundColor= "#537857";
    }

}
